package com.greateamd.timetableasy.server.services;

import java.util.List;

import org.springframework.stereotype.Service;

import com.greateamd.timetableasy.client.services.course.CourseService;
import com.greateamd.timetableasy.domain.Course;
import com.greateamd.timetableasy.domain.StudyPeriod;
import com.greateamd.timetableasy.domain.exceptions.DBServerSideException;
import com.greateamd.timetableasy.server.dao.CourseDAO;

@Service("courseService")
public class CourseServiceImpl implements CourseService {

	private CourseDAO courseDAO;
	public void setCourseDAO(CourseDAO courseDAO) {
		this.courseDAO = courseDAO;
	}
	
	@Override
	public boolean save(Course course) throws DBServerSideException {
		try {
			courseDAO.save(course);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
		return true;
	}

	@Override
	public Course find(int id) throws DBServerSideException{
		try {
			return courseDAO.getById(id);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public List<Course> getAll() throws DBServerSideException {
		try {
			return courseDAO.getAll();
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean remove(Course course) throws DBServerSideException {
		try {
			courseDAO.delete(course);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean update(Course course) throws DBServerSideException {
		try {
			courseDAO.update(course);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public List<Course> getAllOfStudyPeriod(StudyPeriod sp) throws DBServerSideException {
		try {
			return courseDAO.getAllOfStudyPeriod(sp);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

}
